package com.example.supermarket.service.impl;

import com.example.supermarket.mapper.BusinessMapper;
import com.example.supermarket.mapper.ItemMapper;
import com.example.supermarket.pojo.Business;
import com.example.supermarket.pojo.Item;
import com.example.supermarket.service.ItemService;
import com.example.supermarket.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ItemServiceImpl implements ItemService {
    @Autowired
    private ItemMapper itemMapper;
    @Autowired
    private BusinessMapper businessMapper;
    @Override
    public List<Item> getItemByItemId(List<Integer> itemIds) {
        List<Item> list=new ArrayList<>();
        for (Integer itemId : itemIds) {
            Item item = itemMapper.getItemByItemId(itemId);
            list.add(item);
        }
        return list;
    }

    @Override
    public List<Integer> getItemByBusinessId() {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userId=(Integer) map.get("userId");
        Business business=businessMapper.findByUserId(userId);
        Integer businessId=business.getBusinessId();
        return itemMapper.getItemByBusinessId(businessId);
    }
}
